﻿using Compass.Wasm.Shared;
using System.Collections.Generic;

namespace Compass.Wpf.ApiServices.Plans;

public interface IMainPlanService : IBaseService<MainPlanDto>
{
    Task<ApiResponse<MainPlanDto>> UpdateStatusesAsync(Guid id, MainPlanDto dto);
    Task<ApiResponse<MainPlanCountDto>> GetCountAsync();

    Task<ApiResponse<List<MainPlanDto>>> GetBlazorAllAsync(int year, int month, bool annual, bool fromMonth, bool openIssue, bool withIssue);
}
public class MainPlanService : BaseService<MainPlanDto>, IMainPlanService
{
    #region ctor
    private const string ServiceName = "MainPlan";
    private readonly HttpRestClient _client;
    public MainPlanService(HttpRestClient client) : base(client, "MainPlan")
    {
        _client = client;
    }
    #endregion

    #region 扩展
    public async Task<ApiResponse<MainPlanDto>> UpdateStatusesAsync(Guid id, MainPlanDto dto)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Put,
            Route = $"api/{ServiceName}/UpdateStatuses/{id}",
            Param = dto
        };
        return await _client.ExecuteAsync<MainPlanDto>(request);
    }

    public async Task<ApiResponse<MainPlanCountDto>> GetCountAsync()
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/Count"
        };
        return await _client.ExecuteAsync<MainPlanCountDto>(request);
    }

    public async Task<ApiResponse<List<MainPlanDto>>> GetBlazorAllAsync(int year, int month, bool annual, bool fromMonth, bool openIssue, bool withIssue)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/Blazor/All?year={year}&month={month}&annual={annual}&fromMonth={fromMonth}&openIssue={openIssue}&withIssue={withIssue}"
        };
        return await _client.ExecuteAsync<List<MainPlanDto>>(request);
    }
    #endregion
}